package com.zht.filter;

import jakarta.servlet.*;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import lombok.extern.slf4j.Slf4j;


import java.io.IOException;

@Slf4j
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("MyFilter 初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //在请求之前
        log.info("MyFilter 请求开始");

        //放行
        filterChain.doFilter(servletRequest,servletResponse);

        //之后
        log.info("MyFilter 请求之后");

    }

    @Override
    public void destroy() {
        log.info("MyFilter 销毁了");
    }
}
